home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
glstuff.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
6KB
|
335 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* glstuff -
* Graphics library support.
*
* Paul Haeberli - 1988
*
*/
#include "math.h"
#include "gl.h"
#include "device.h"
#include "stdio.h"
#include "port.h"
#include "bitmap.h"
#include "obj.h"
#include "gfxmach.h"
pupcolor(c)
int c;
{
color(c);
}
greybase()
{
return 512;
}
extern int system(const char *);
savewindow(name)
char *name;
{
char cmd[256];
long xorg, yorg;
long xsize, ysize;
getorigin(&xorg,&yorg);
getsize(&xsize,&ysize);
sprintf(cmd,"scrsave %s %d %d %d %d\n",name,xorg,xorg+xsize-1,yorg,yorg+ysize-1);
system(cmd);
}
printwindow()
{
savewindow("/usr/tmp/print.rgb");
system("printimage /usr/tmp/print.rgb");
system("rm /usr/tmp/print.rgb");
ringbell();
ringbell();
}
saveframe()
{
char oneline[512];
savewindow("frame.rgb");
system("izoom frame.rgb vidframe.rgb 646");
system("rcp vidframe.rgb guest@cl2devi:/usr/people/paul");
sprintf(oneline,"/usr/bsd/rsh cl2devi -l paul vid/expose vidframe.rgb");
system(oneline);
system("rm frame.rgb vidframe.rgb");
}
static int outframe = 0;
savemovieframe()
{
char oneline[256];
if(outframe++ == 0) {
system("rm -fr ssmovie");
system("mkdir ssmovie");
}
sprintf(oneline,"ssmovie/%03d.rgb",outframe);
savewindow(oneline);
ringbell();
ringbell();
}
static int gfxmach = -1;
static long setnear, setfar;
gfxmachine()
{
char str[256];
if(gfxmach>=0)
return gfxmach;
gversion(str);
if(strncmp(str,"GL4DGT-",7) == 0)
return MACH4DGT;
if(strncmp(str,"GL4DPI",6) == 0) {
if(getplanes()<=8)
return MACH4D8;
else
return MACH4DPI;
}
if(strncmp(str,"GL4D-",5) == 0)
return MACH4D;
if(strncmp(str,"GL3D-",5) == 0)
return MACH3D;
if(strncmp(str,"GL4DLG-",7) == 0)
return MACH4DVGX;
if(getplanes()<=8)
return MACH4D8;
else
return MACH4DVGX;
}
smartsetdepth()
{
fsetdepth(0.01,0.99);
}
static int firsted;
static double limnear, limdel;
fsetdepth(near,far)
float near, far;
{
int inear, ifar;
if(!firsted) {
limnear = getgdesc(GD_ZMIN);
limdel = (double)getgdesc(GD_ZMAX)-limnear;
firsted = 1;
}
if(near<0.0)
near = 0.0;
if(far<0.0)
far = 0.0;
if(near>1.0)
near = 1.0;
if(far>1.0)
far = 1.0;
inear = (limnear+near*limdel)+0.499;
ifar = (limnear+far *limdel)+0.499;
zviewport(inear,ifar);
}
zviewport(near,far)
long near, far;
{
lsetdepth(near,far);
setnear = near;
setfar = far;
}
getzviewport(lnear,lfar)
long *lnear, *lfar;
{
*lnear=setnear;
*lfar=setfar;
}
drawmeshimage(imgdata,xsize,ysize)
unsigned long *imgdata;
int xsize, ysize;
{
drawquadlimage(imgdata,xsize,ysize);
}
drawquadlimage(imgdata,xsize,ysize)
unsigned long *imgdata;
int xsize, ysize;
{
int x, y;
unsigned long *dptr;
dptr = imgdata;
pushmatrix();
scale(1.0/(xsize-1),1.0/(ysize-1),1.0);
for(y=0; y<(ysize-1); y++) {
quadrow(dptr,dptr+xsize,xsize,y);
dptr += xsize;
}
popmatrix();
}
quadrow(y0,y1,n,y)
unsigned long *y0, *y1;
int n, y;
{
float v0[2], v1[2];
int x;
v0[1] = y+0;
v1[1] = y+1;
bgntmesh();
for(x=0; x<n; x++) {
v1[0] = x;
cpack(*y1++);
v2f(v1);
v0[0] = x;
cpack(*y0++);
v2f(v0);
}
endtmesh();
}
drawtrilimage(imgdata,xsize,ysize)
unsigned long *imgdata;
int xsize, ysize;
{
int x, y, dxsize;
unsigned long *dptr;
ysize = (ysize-1)/2;
dxsize = 2*((xsize-1)/2);
dptr = imgdata;
pushmatrix();
scale(1.0/(dxsize-1),1.0/ysize,1.0);
for(y=0; y<ysize; y++) {
trirow(dptr,dptr+2*xsize,dxsize,y);
dptr += 2*xsize;
}
popmatrix();
}
trirow(y0,y1,n,y)
unsigned long *y0, *y1;
int n, y;
{
float v0[2], v1[2];
unsigned long *temp;
int x;
if(y&1) {
temp = y0;
y0 = y1;
y1 = temp;;
v0[1] = y+1;
v1[1] = y+0;
} else {
v0[1] = y+0;
v1[1] = y+1;
}
bgntmesh();
v1[0] = 0;
cpack(y1[0]);
v2f(v1);
for(x=0; x<n; x++) {
if(x&1) {
v1[0] = x;
cpack(y1[x]);
v2f(v1);
} else {
v0[0] = x;
cpack(y0[x]);
v2f(v0);
}
}
if(n&1) {
v1[0] = n-1;
cpack(y1[n-1]);
v2f(v1);
} else {
v0[0] = n-1;
cpack(y0[n-1]);
v2f(v0);
}
endtmesh();
}
drawrectlimage(imgdata,xsize,ysize)
unsigned long *imgdata;
int xsize, ysize;
{
int x, y;
unsigned long *dptr;
dptr = imgdata;
pushmatrix();
scale(1.0/(xsize-1),1.0/(ysize-1),1.0);
for(y=0; y<ysize-1; y++) {
rectrow(dptr,dptr+xsize,xsize-1,y);
dptr += xsize;
}
popmatrix();
}
rectrow(y0,y1,n,y)
unsigned long *y0, *y1;
int n, y;
{
float v0[2];
int x;
for(x=0; x<n; x++) {
bgnpolygon();
v0[0] = x;
v0[1] = y;
cpack(y0[0]);
v2f(v0),
v0[0] = x+1;
v0[1] = y;
cpack(y0[1]);
v2f(v0),
v0[0] = x+1;
v0[1] = y+1;
cpack(y1[1]);
v2f(v0),
v0[0] = x;
v0[1] = y+1;
cpack(y1[0]);
v2f(v0),
endpolygon();
y0++;
y1++;
}
}